﻿using Microsoft.Win32;
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ServEvo.Layout.Interfaces;
using ServEvo.Layout.Enum;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using System.Net;
using System.IO;
using ServEvo.Layout.Structures;
using ServEvo.ServControl;

namespace ServEvo.ServConfig
{
    class ConfigurationManager : IDisposable
    {
        private SNetwork _sNetworkInfo;
        
        private static ConfigurationManager manager;
        private UpdateManager _updateManager;
        private ConfigurationData _configurationData;

        private ManagementType _typeManagementHTTP = ManagementType.NotManaged;
        private ManagementType _typeManagementMySQL = ManagementType.NotManaged;
        private ManagementType _typeManagementPHP = ManagementType.NotManaged;
        private ManagementType _typeManagementFTP = ManagementType.NotManaged;
        private ManagementType _typeManagementSMTP = ManagementType.NotManaged;
        private bool _isHTTPManaged;
        private bool _isMySQLManaged;
        private bool _isPHPManaged;
        private bool _isFTPManaged;
        private bool _isSMTPManaged;

        private MainManager _HTTPManager;
        private MainManager _MySQLManager;
        private MainManager _PHPManager;
        private MainManager _FTPManager;
        private MainManager _SMTPManager;

        private Dictionary<string, object> _listServer;
        private Dictionary<int, SPortDetail> _listPort;

        public MainManager HTTPManager
        {
            get { return _HTTPManager; }
            set
            {
                if (value is MainManager)
                {
                    _configurationData.HTTPManager = value.getManagerId();
                }
                _HTTPManager = value;
            }
        }
        public MainManager MySQLManager
        {
            get { return _MySQLManager; }
            set
            {
                if (value is MainManager)
                {
                    _configurationData.MySQLManager = value.getManagerId();
                }
                _MySQLManager = value;
            }
        }
        public MainManager PHPManager
        {
            get { return _PHPManager; }
            set
            {
                if (value is MainManager)
                {
                    _configurationData.PHPManager = value.getManagerId();
                }
                _PHPManager = value;
            }
        }
        public MainManager FTPManager
        {
            get { return _FTPManager; }
            set
            {
                if (value is MainManager)
                {
                    _configurationData.FTPManager = value.getManagerId();
                }
                _FTPManager = value;
            }
        }
        public MainManager SMTPManager
        {
            get { return _SMTPManager; }
            set
            {
                if (value is MainManager)
                {
                    _configurationData.SMTPManager = value.getManagerId();
                }
                _SMTPManager = value;
            }
        }

        public SNetwork sNetworkInfo
        {
            get { return _sNetworkInfo; }
        }
        public Dictionary<int, SPortDetail> ListPort
        {
            get { return _listPort; }
        }
        public Dictionary<string, object> ListServer
        {
            get { return _listServer; }
        }
        public ConfigurationData ConfigurationData
        {
            get { return _configurationData; }
        }

        //tmp
        public string apacheVersion = "";
        public string phpVersion = "";
        public string mysqlVersion = "";
        public string ftpVersion = "";
        public string smtpVersion = "";

        public bool isHTTPManaged
        {
            get { return _isHTTPManaged; }
        }
        public bool isMySQLManaged
        {
            get { return _isMySQLManaged; }
        }
        public bool isPHPManaged
        {
            get { return _isPHPManaged; }
        }
        public bool isFTPManaged
        {
            get { return _isFTPManaged; }
        }
        public bool isSMTPManaged
        {
            get { return _isSMTPManaged; }
        }
        
        private ConfigurationManager()
        {
            this._configurationData = ConfigurationData.getManager();
            this.checkNetworkInfo();
            checkPortAvailable();
            loadConfiguration();
        }

        public void loadConfiguration()
        {
            this.HTTPManager = new MainManager();
            this.MySQLManager = new MainManager();
            this.PHPManager = new MainManager();
            this.FTPManager = new MainManager();
            this.SMTPManager = new MainManager();
            _configurationData.load();
            _configurationData.refrechData();

            this._typeManagementHTTP = ManagementType.NotManaged;
            this._typeManagementMySQL = ManagementType.NotManaged;
            this._typeManagementPHP = ManagementType.NotManaged;
            this._typeManagementFTP = ManagementType.NotManaged;
            this._typeManagementSMTP = ManagementType.NotManaged;
            this._isHTTPManaged = false;
            this._isMySQLManaged = false;
            this._isPHPManaged = false;
            this._isFTPManaged = false;
            this._isSMTPManaged = false;

            checkConfigurationFile();
        }

        public static ConfigurationManager getManager()
        {
            if (ConfigurationManager.manager == null)
            {
                ConfigurationManager.manager = new ConfigurationManager();
            }

            return ConfigurationManager.manager;
        }
        public void checkConfigurationFile()
        {
            this._listServer = new Dictionary<string, object>();
            if (_configurationData.UseBuildIn)
            {
                checkBuildInConfig();
            }
            else
            {
                List<string> filezillaInstallDir = FilezillaFTPManager.checkInstallDir(_configurationData);
                initFileZilla(filezillaInstallDir);
                
                List<string> easyphpInstallDir = EasyPHPManager.checkInstallDir(_configurationData);
                initEasyPHP(easyphpInstallDir);
                
                List<string> wampInstallDir = WampManager.checkInstallDir(_configurationData);
                initWamp(wampInstallDir);

                List<string> freesmtpInstallDir = FreeSMTPManager.checkInstallDir(_configurationData);
                initFreeSMTP(freesmtpInstallDir);
            }
        }

        private void checkBuildInConfig()
        {
            //TODO manager bin/config.ini
            if (!String.IsNullOrEmpty(_configurationData.InstallDir))
            {
                string sFullInstallDir = String.Empty;
                if (_configurationData.InstallDir.Substring(_configurationData.InstallDir.Length - 1, 1) != @"\") _configurationData.InstallDir += @"\";

                if (!_configurationData.InstallDir[1].Equals(':'))
                    sFullInstallDir = System.Windows.Forms.Application.StartupPath + _configurationData.InstallDir;
                else
                    sFullInstallDir = _configurationData.InstallDir;

                if (Directory.Exists(sFullInstallDir))
                {
                    if (File.Exists(sFullInstallDir + "config.ini"))
                    {
                        IniFile configurationBuildInFile = new IniFile();
                        configurationBuildInFile.Load(sFullInstallDir + "config.ini");
                        checkBuildInServices(_configurationData.InstallDir, configurationBuildInFile);
                    }
                }
            }
        }

        public void checkBuildInServices(string CF_sInstallDir, IniFile configurationBuildInFile)
        {
            IniFile.IniSection configHTTP = configurationBuildInFile.GetSection("HTTP");
            IniFile.IniSection configPHP = configurationBuildInFile.GetSection("PHP");
            IniFile.IniSection configMySQL = configurationBuildInFile.GetSection("MySQL");
            IniFile.IniSection configFTP = configurationBuildInFile.GetSection("FTP");
            IniFile.IniSection configSMTP = configurationBuildInFile.GetSection("SMTP");
            ApacheManager oBuildinApache = ApacheManager.checkConfiguration(CF_sInstallDir, configHTTP);
            if (oBuildinApache != null)
            {
                if (!this._listServer.ContainsKey(oBuildinApache.getManagerId()))
                {
                    this._listServer.Add(oBuildinApache.getManagerId(), oBuildinApache);
                    this._HTTPManager = oBuildinApache;
                    if (oBuildinApache.IsServiceInstalled)
                        _typeManagementHTTP = ManagementType.Service;
                    else
                        _typeManagementHTTP = ManagementType.Serveur;
                    _isHTTPManaged = true;
                }
            }
        }
        private void initEasyPHP(List<string> _installDir)
        {
            string easyPHPApacheProcess = "apache\\bin\\apache.exe";
            string easyPHPMySQLProcess = "mysql\\bin\\mysqld.exe";
            foreach (string sEasyPHP in _installDir)
            {
                EasyPHPManager oEasyPHP = new EasyPHPManager(sEasyPHP, easyPHPApacheProcess, easyPHPMySQLProcess);
                if (!this._listServer.ContainsKey(oEasyPHP.getManagerId()))
                {
                    this._listServer.Add(oEasyPHP.getManagerId(), oEasyPHP);
                    if (_configurationData.HTTPManager == oEasyPHP.ToString() && !_configurationData.UseBuildIn)
                    {
                        this._HTTPManager = oEasyPHP;
                        _typeManagementHTTP = ManagementType.Serveur;
                        _isHTTPManaged = true;
                    }
                    if (_configurationData.MySQLManager == oEasyPHP.ToString() && !_configurationData.UseBuildIn)
                    {
                        this._MySQLManager = oEasyPHP;
                        _typeManagementMySQL = ManagementType.Serveur;
                        _isMySQLManaged = true;
                    }
                }
            }
        }
        private void initWamp(List<string> _installDir)
        {
            foreach (string sWamp in _installDir)
            {
                WampManager oWamp = new WampManager(sWamp, Properties.Resources.SERVICE_WAMPAPACHE, Properties.Resources.SERVICE_WAMPMYSQL);
                if (!this._listServer.ContainsKey(oWamp.getManagerId()))
                {
                    this._listServer.Add(oWamp.getManagerId(), oWamp);
                    if (_configurationData.HTTPManager == oWamp.ToString() && !_configurationData.UseBuildIn)
                    {
                        this._HTTPManager = oWamp;
                        _typeManagementHTTP = ManagementType.Service;
                        _isHTTPManaged = true;
                    }
                    if (_configurationData.MySQLManager == oWamp.ToString() && !_configurationData.UseBuildIn)
                    {
                        this._MySQLManager = oWamp;
                        _typeManagementMySQL = ManagementType.Service;
                        _isMySQLManaged = true;
                    }
                }
            }
        }
        private void initFileZilla(List<string> _installDir)
        {
            foreach (string sFileZilla in _installDir)
            {
                FilezillaFTPManager oFilezilla = new FilezillaFTPManager(sFileZilla, Properties.Resources.SERVICE_FILEZILLA);
                if (!this._listServer.ContainsKey(oFilezilla.getManagerId()))
                {
                    this._listServer.Add(oFilezilla.getManagerId(), oFilezilla);
                    if (_configurationData.FTPManager == oFilezilla.ToString() && !_configurationData.UseBuildIn)
                    {
                        this._FTPManager = oFilezilla;
                        _typeManagementFTP = ManagementType.Service;
                        _isFTPManaged = true;
                    }
                }
            }
        }
        private void initFreeSMTP(List<string> _installDir)
        {
            foreach (string sFreeSMTP in _installDir)
            {
                FreeSMTPManager oFreeSMTP = new FreeSMTPManager(sFreeSMTP, Properties.Resources.PROCESS_FREESMTP);
                if (!this._listServer.ContainsKey(oFreeSMTP.getManagerId()))
                {
                    this._listServer.Add(oFreeSMTP.getManagerId(), oFreeSMTP);
                    if (_configurationData.SMTPManager == oFreeSMTP.ToString() && !_configurationData.UseBuildIn)
                    {
                        this._SMTPManager = oFreeSMTP;
                        _typeManagementSMTP = ManagementType.Serveur;
                        _isSMTPManaged = true;
                    }
                }
            }
        }

        private void checkNetworkInfo()
        {
            _sNetworkInfo = new SNetwork();
            _sNetworkInfo.hostName = IPGlobalProperties.GetIPGlobalProperties().HostName;

            foreach (NetworkInterface networkCard in NetworkInterface.GetAllNetworkInterfaces())
            {
                IPInterfaceProperties ipInterface = networkCard.GetIPProperties();
                foreach (IPAddress dhcpAddr in ipInterface.DhcpServerAddresses)
                {
                    if (dhcpAddr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
                    {
                        if (dhcpAddr.IsIPv6LinkLocal)
                        {
                            _sNetworkInfo.ipV6DHCP = dhcpAddr;
                        }
                    }
                    if (dhcpAddr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        _sNetworkInfo.ipV4DHCP = dhcpAddr;
                    }

                }
                foreach (IPAddress dnsAddr in ipInterface.DnsAddresses)
                {
                    if (dnsAddr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
                    {
                        if (dnsAddr.IsIPv6LinkLocal)
                        {
                            _sNetworkInfo.ipV6DNS = dnsAddr;
                        }
                    }
                    if (dnsAddr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        _sNetworkInfo.ipV4DNS = dnsAddr;
                    }

                }
                foreach (IPAddress localAddr in Dns.GetHostAddresses(Dns.GetHostName()))
                {
                    if (localAddr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
                    {
                        if (localAddr.IsIPv6LinkLocal)
                        {
                            _sNetworkInfo.ipV6Local = localAddr;
                        }
                    }
                    if (localAddr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        _sNetworkInfo.ipV4Local = localAddr;
                        break;
                    }
                }
                foreach (GatewayIPAddressInformation gatewayAddr in ipInterface.GatewayAddresses)
                {
                    if (gatewayAddr.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
                    {
                        if (gatewayAddr.Address.IsIPv6LinkLocal)
                        {
                            _sNetworkInfo.ipV6Gate = gatewayAddr.Address;
                        }
                    }
                    if (gatewayAddr.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        _sNetworkInfo.macAddr = networkCard.GetPhysicalAddress();
                        _sNetworkInfo.ipV4Gate = gatewayAddr.Address;
                    }

                }

            }
        }
        public void checkPortAvailable()
        {
            this._listPort = new Dictionary<int, SPortDetail>();
            this._listPort.Add(21, new SPortDetail(21));
            this._listPort.Add(25, new SPortDetail(25));
            this._listPort.Add(80, new SPortDetail(80));
            this._listPort.Add(81, new SPortDetail(81));
            this._listPort.Add(3306, new SPortDetail(3306));

            IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
            TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();
            IPEndPoint[] tcpListeners = ipGlobalProperties.GetActiveTcpListeners();


            foreach (IPEndPoint listener in tcpListeners)
            {
                if (this._listPort.Keys.Contains(listener.Port))
                {
                    SPortDetail port = this._listPort[listener.Port];
                    port.IsAvailable = false;
                    port.State = listener.ToString();
                    this._listPort[listener.Port] = port;
                }
            }
        }

        public ServiceStatut getStatutHTTP()
        {
            ServiceStatut statutCode;
            if (_configurationData.UseBuildIn)
                statutCode = ServiceStatut.NotDownloaded;
            else
                statutCode = ServiceStatut.NotConfigurated;

            if (_isHTTPManaged && _HTTPManager != null)
            {
                statutCode = ServiceStatut.Stopped;
                if (this._typeManagementHTTP == ManagementType.Service)
                {
                    IService service = this._listServer[_HTTPManager.getManagerId()] as IService;
                    if (service != null)
                    {
                        if (service.isServiceStarted(Service.HTTP)) statutCode = ServiceStatut.Started;
                    }
                }
                if (this._typeManagementHTTP == ManagementType.Serveur)
                {
                    IServeur serveur = this._listServer[_HTTPManager.getManagerId()] as IServeur;
                    if (serveur != null)
                    {
                        if (serveur.isServeurStarted(Service.HTTP)) statutCode = ServiceStatut.Started;
                    }
                }
            }
            return statutCode;
        }
        public void startHTTP()
        {
            if (_isHTTPManaged && _HTTPManager != null)
            {
                if (this._typeManagementHTTP == ManagementType.Service)
                {
                    IService service = this._listServer[_HTTPManager.getManagerId()] as IService;
                    if (service != null)
                    {
                        service.startService(Service.HTTP);
                    }
                }
                if (this._typeManagementHTTP == ManagementType.Serveur)
                {
                    IServeur serveur = this._listServer[_HTTPManager.getManagerId()] as IServeur;
                    if (serveur != null)
                    {
                        serveur.startServeur(Service.HTTP);
                    }
                }
            }
        }
        public void restartHTTP()
        {
            if (_isHTTPManaged && _HTTPManager != null)
            {
                if (this._typeManagementHTTP == ManagementType.Service)
                {
                    IService service = this._listServer[_HTTPManager.getManagerId()] as IService;
                    if (service != null)
                    {
                        service.restartService(Service.HTTP);
                    }
                }
                if (this._typeManagementHTTP == ManagementType.Serveur)
                {
                    IServeur serveur = this._listServer[_HTTPManager.getManagerId()] as IServeur;
                    if (serveur != null)
                    {
                        serveur.restartServeur(Service.HTTP);
                    }
                }
            }
        }
        public void stopHTTP()
        {
            if (_isHTTPManaged && _HTTPManager != null)
            {
                if (this._typeManagementHTTP == ManagementType.Service)
                {
                    IService service = this._listServer[_HTTPManager.getManagerId()] as IService;
                    if (service != null)
                    {
                        service.stopService(Service.HTTP);
                    }
                }
                if (this._typeManagementHTTP == ManagementType.Serveur)
                {
                    IServeur serveur = this._listServer[_HTTPManager.getManagerId()] as IServeur;
                    if (serveur != null)
                    {
                        serveur.stopServeur(Service.HTTP);
                    }
                }
            }
        }

        public ServiceStatut getStatutMySQL()
        {
            ServiceStatut statutCode;
            if (_configurationData.UseBuildIn)
                statutCode = ServiceStatut.NotDownloaded;
            else
                statutCode = ServiceStatut.NotConfigurated;

            if (_isMySQLManaged && _MySQLManager!= null)
            {
                statutCode = ServiceStatut.Stopped;

                if (this._typeManagementMySQL == ManagementType.Service)
                {
                    IService service = this._listServer[_MySQLManager.getManagerId()] as IService;
                    if (service != null)
                    {
                        if (service.isServiceStarted(Service.MySQL)) statutCode = ServiceStatut.Started;
                    }
                }
                if (this._typeManagementMySQL == ManagementType.Serveur)
                {
                    IServeur serveur = this._listServer[_MySQLManager.getManagerId()] as IServeur;
                    if (serveur != null)
                    {
                        if (serveur.isServeurStarted(Service.MySQL)) statutCode = ServiceStatut.Started;
                    }
                }
            }
            return statutCode;
        }
        public void startMySQL()
        {
            if (_isHTTPManaged && _MySQLManager != null)
            {
                if (this._typeManagementMySQL == ManagementType.Service)
                {
                    IService service = this._listServer[_MySQLManager.getManagerId()] as IService;
                    if (service != null)
                    {
                        service.startService(Service.MySQL);
                    }
                }
                if (this._typeManagementMySQL == ManagementType.Serveur)
                {
                    IServeur serveur = this._listServer[_MySQLManager.getManagerId()] as IServeur;
                    if (serveur != null)
                    {
                        serveur.startServeur(Service.MySQL);
                    }
                }
            }
        }
        public void restartMySQL()
        {
            if (_isHTTPManaged && _MySQLManager != null)
            {
                if (this._typeManagementMySQL == ManagementType.Service)
                {
                    IService service = this._listServer[_MySQLManager.getManagerId()] as IService;
                    if (service != null)
                    {
                        service.restartService(Service.MySQL);
                    }
                }
                if (this._typeManagementMySQL == ManagementType.Serveur)
                {
                    IServeur serveur = this._listServer[_MySQLManager.getManagerId()] as IServeur;
                    if (serveur != null)
                    {
                        serveur.restartServeur(Service.MySQL);
                    }
                }
            }
        }
        public void stopMySQL()
        {
            if (_isHTTPManaged && _MySQLManager != null)
            {
                if (this._typeManagementMySQL == ManagementType.Service)
                {
                    IService service = this._listServer[_MySQLManager.getManagerId()] as IService;
                    if (service != null)
                    {
                        service.stopService(Service.MySQL);
                    }
                }
                if (this._typeManagementMySQL == ManagementType.Serveur)
                {
                    IServeur serveur = this._listServer[_MySQLManager.getManagerId()] as IServeur;
                    if (serveur != null)
                    {
                        serveur.stopServeur(Service.MySQL);
                    }
                }
            }
        }

        public ServiceStatut getStatutSMTP()
        {
            ServiceStatut statutCode;
            if (_configurationData.UseBuildIn)
                statutCode = ServiceStatut.NotDownloaded;
            else
                statutCode = ServiceStatut.NotConfigurated;

            if (_isSMTPManaged && _SMTPManager != null)
            {
                statutCode = ServiceStatut.Stopped;
                if (this._typeManagementSMTP == ManagementType.Service)
                {
                    //
                }
                if (this._typeManagementSMTP == ManagementType.Serveur)
                {
                    IServeur serveur = this._listServer[_SMTPManager.getManagerId()] as IServeur;
                    if (serveur != null)
                    {
                        if (serveur.isServeurStarted(Service.SMTP)) statutCode = ServiceStatut.Started;
                    }
                }
            }
            return statutCode;
        }
        public void startSMTP()
        {
            if (_isSMTPManaged && _SMTPManager != null)
            {
                if (this._typeManagementSMTP == ManagementType.Service)
                {
                    //
                }
                if (this._typeManagementSMTP == ManagementType.Serveur)
                {
                    IServeur serveur = this._listServer[_SMTPManager.getManagerId()] as IServeur;
                    if (serveur != null)
                    {
                        serveur.startServeur(Service.SMTP);
                    }
                }
            }
        }
        public void restartSMTP()
        {
            if (_isSMTPManaged && _SMTPManager != null)
            {
                if (this._typeManagementSMTP == ManagementType.Service)
                {
                    //
                }
                if (this._typeManagementSMTP == ManagementType.Serveur)
                {
                    IServeur serveur = this._listServer[_SMTPManager.getManagerId()] as IServeur;
                    if (serveur != null)
                    {
                        serveur.restartServeur(Service.SMTP);
                    }
                }
            }
        }
        public void stopSMTP()
        {
            if (_isSMTPManaged && _SMTPManager != null)
            {
                if (this._typeManagementSMTP == ManagementType.Service)
                {
                    //
                }
                if (this._typeManagementSMTP == ManagementType.Serveur)
                {
                    IServeur serveur = this._listServer[_SMTPManager.getManagerId()] as IServeur;
                    if (serveur != null)
                    {
                        serveur.stopServeur(Service.SMTP);
                    }
                }
            }
        }

        public ServiceStatut getStatutFTP()
        {
            ServiceStatut statutCode;
            if (_configurationData.UseBuildIn)
                statutCode = ServiceStatut.NotDownloaded;
            else
                statutCode = ServiceStatut.NotConfigurated;

            if (_isFTPManaged && _FTPManager != null)
            {
                statutCode = ServiceStatut.Stopped;

                if (this._typeManagementFTP == ManagementType.Service)
                {
                    IService service = this._listServer[_FTPManager.getManagerId()] as IService;
                    if (service != null)
                    {
                        if (service.isServiceStarted(Service.FTP)) statutCode = ServiceStatut.Started;
                    }
                }
                if (this._typeManagementFTP == ManagementType.Serveur)
                {
                    //
                }
            }
            return statutCode;
        }
        public void startFTP()
        {
            if (_isFTPManaged && _FTPManager != null)
            {
                if (this._typeManagementFTP == ManagementType.Service)
                {
                    IService service = this._listServer[_FTPManager.getManagerId()] as IService;
                    if (service != null)
                    {
                        service.startService(Service.FTP);
                    }
                }
                if (this._typeManagementFTP == ManagementType.Serveur)
                {
                    //
                }
            }
        }
        public void restartFTP()
        {
            if (_isFTPManaged && _FTPManager != null)
            {
                if (this._typeManagementFTP == ManagementType.Service)
                {
                    IService service = this._listServer[_FTPManager.getManagerId()] as IService;
                    if (service != null)
                    {
                        service.restartService(Service.FTP);
                    }
                }
                if (this._typeManagementFTP == ManagementType.Serveur)
                {
                    //
                }
            }
        }
        public void stopFTP()
        {
            if (_isFTPManaged && _FTPManager != null)
            {
                if (this._typeManagementFTP == ManagementType.Service)
                {
                    IService service = this._listServer[_FTPManager.getManagerId()] as IService;
                    if (service != null)
                    {
                        service.stopService(Service.FTP);
                    }
                }
                if (this._typeManagementFTP == ManagementType.Serveur)
                {
                    //
                }
            }
        }

        public void Dispose()
        {
            foreach (object serveur in _listServer)
            {
                IDisposable disposableServeur = serveur as IDisposable;
                if (disposableServeur != null)
                    disposableServeur.Dispose();
            }
        }
    }
}
